
# -*- coding: utf-8 -*-

import json
import urllib2
from config.Config import USER_WEBSERVICE_LIST, USERS_WEBSERVICE_URL

def loadUsersFromWebservice():
	response = urllib2.urlopen(urllib2.Request(USERS_WEBSERVICE_URL))
	respData = response.read()
	parsed = json.loads(unicode(respData, "ISO-8859-1"))
	response.close()
	USER_WEBSERVICE_LIST.clear()
	try:
		for emp in parsed["employees"]:
			USER_WEBSERVICE_LIST[emp["id"]] = unicode(emp["nombre"])
	except:
		USER_WEBSERVICE_LIST.clear()

def getNameByUserIdFromWebService(username):
	if USER_WEBSERVICE_LIST.has_key(username):
		return USER_WEBSERVICE_LIST[username]
	return "[SIN NOMBRE]"
